﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>发票查询</title> 
    <link rel="stylesheet" type="text/css" href="../Content/Css/OperaMasksUI/default/om-all.css" />
    <link rel="stylesheet" type="text/css" href="../Content/Css/list.css" />
    <script type="text/javascript" src="../Scripts/jquery.1.6.3.min.js"></script>
    <script type="text/javascript" src="../Scripts/json2.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/operamasks-ui.min.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/Plugin/om-yj-container.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/jquery.artDialog.js?skin=default"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/plugins/iframeTools.js"></script>
    <script type="text/javascript">
        var detailPanel, listGrid, detailGrid, colData, detailColData, searchPanel, defaultSort, defaultWhere, validatorForm, submitForm, currentUID, currentGIndex = -1, genRenderCheckbox, genRenderDateformat;
        var showSearchPanel, showToolBar, showDetialForm, controlBtn, oldRowData, detailForm, goOn = true, DoFlag = true, ifh;
        var actionRoot = "../handler/ajax.ashx?type=AjaxSystem", comboxBankData = [], comboxTypeData = [], comboxStatusData = [], genRenderDateformat, genRenderDateformatSS;

        $(document).ready(function () {
            $.ajax({
                cache: false, async: false,
                url: '../handler/ajax.ashx?type=AjaxSystem&method=loginIn',
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载用户信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    if (data.IsError) {
                        goOn = false;
                        $.omMessageBox.alert({
                            content: '发现错误<BR>' + data.Message,
                            onClose: function () {
                                window.top.location.href = decodeURIComponent("../Index.aspx");
                            }
                        });
                    }
                    else {
                        goOn = true;
                        currentUID = data.Data.userid;
                        currentDept = data.Data.deptid;
                        currentDeptName = data.Data.deptname;
                    }
                },
                error: function (result) {
                    goOn = false;
                    $.omMessageBox.alert({
                        content: '发现错误<BR>' + result.status,
                        onClose: function () {
                            window.top.location.href = decodeURIComponent("../Index.aspx");
                        }
                    });
                }
            });
            var element = $('body').omBorderLayout({
                fit: true,
                spacing: 0,
                panels: [
                {
                    id: "center-panel",
                    header: false,
                    title: "中间模块",
                    region: "center"
                }, {
                    id: "west-panel",
                    resizable: true,
                    collapsible: true,
                    title: "<span style='color:#15428B;font-weight: bold;padding:6px;'>查询条件</span>",
                    region: "west",
                    width: 230
                },
                {
                    id: "south-panel",
                    region: "south",
                    header: false,
                    resizable: false,
                    collapsible: false,
                    height: 50
                },
                {
                    id: "east-panel",
                    region: "east",
                    header: false,
                    resizable: false,
                    collapsible: false,
                    width:400
                }
                ]
            });
            showSearchPanel();

            //Grid Column 
            colData = [
                { header: '发票状态', name: 'InvoiceStatus', width: 50, align: 'center' },
                { header: '发票号码', name: 'InvoiceNo', width:100, align: 'center' },
                { header: '发票类型', name: 'InvoiceType', width: 120, align: 'center' },
                { header: '开票时间', name: 'InvoiceDate', width: 80, align: 'center', renderer: genRenderDateformatSS },
                { header: '销货名称', name: 'InvoiceFMTitle', width: 200, align: 'center' },
                { header: '销货税号', name: 'InvoiceFMTaxNo', width: 200, align: 'center' },
                { header: '销货地址', name: 'InvoiceFMAddr', width: 200, align: 'center' },
                { header: '销货账号', name: 'InvoiceFMAccount', width: 200, align: 'center' },
                { header: '金额', name: 'Amount', width: 80, align: 'center' },
                { header: '税额', name: 'Tax', width: 80, align: 'center' },
                { header: '商品名称1', name: 'FeeType1', width: 60, align: 'center' },
                { header: '规格1', name: 'Model1', width: 30, align: 'center' },
                { header: '单位1', name: 'Unit1', width: 30, align: 'center' },
                { header: '数量1', name: 'QTY1', width: 30, align: 'center' },
                { header: '单价1', name: 'PRICE1', width: 50, align: 'center' },
                { header: '金额1', name: 'Amount1', width: 50, align: 'center' },
                { header: '税率1', name: 'TaxRate1', width: 30, align: 'center' },
                { header: '税额1', name: 'Tax1', width: 30, align: 'center' },
                { header: '商品名称2', name: 'FeeType2', width: 60, align: 'center' },
                { header: '规格2', name: 'Model2', width: 30, align: 'center' },
                { header: '单位2', name: 'Unit2', width: 30, align: 'center' },
                { header: '数量2', name: 'QTY2', width: 30, align: 'center' },
                { header: '单价2', name: 'PRICE2', width: 50, align: 'center' },
                { header: '金额2', name: 'Amount2', width: 50, align: 'center' },
                { header: '税率2', name: 'TaxRate2', width: 30, align: 'center' },
                { header: '税额2', name: 'Tax1', width: 30, align: 'center' },
                { header: '商品名称3', name: 'FeeType3', width: 60, align: 'center' },
                { header: '规格3', name: 'Model3', width: 30, align: 'center' },
                { header: '单位3', name: 'Unit3', width: 30, align: 'center' },
                { header: '数量3', name: 'QTY3', width: 30, align: 'center' },
                { header: '单价3', name: 'PRICE3', width: 50, align: 'center' },
                { header: '金额3', name: 'Amount3', width: 50, align: 'center' },
                { header: '税率3', name: 'TaxRate3', width: 30, align: 'center' },
                { header: '税额3', name: 'Tax1', width: 30, align: 'center' },
                { header: '商品名称4', name: 'FeeType4', width: 60, align: 'center' },
                { header: '规格4', name: 'Model4', width: 30, align: 'center' },
                { header: '单位4', name: 'Unit4', width: 30, align: 'center' },
                { header: '数量4', name: 'QTY4', width: 30, align: 'center' },
                { header: '单价4', name: 'PRICE4', width: 50, align: 'center' },
                { header: '金额4', name: 'Amount4', width: 50, align: 'center' },
                { header: '税率4', name: 'TaxRate4', width: 30, align: 'center' },
                { header: '税额4', name: 'Tax4', width: 30, align: 'center' },
                { header: '商品名称5', name: 'FeeType5', width: 60, align: 'center' },
                { header: '规格5', name: 'Model5', width: 30, align: 'center' },
                { header: '单位5', name: 'Unit5', width: 30, align: 'center' },
                { header: '数量5', name: 'QTY5', width: 30, align: 'center' },
                { header: '单价5', name: 'PRICE5', width: 50, align: 'center' },
                { header: '金额5', name: 'Amount5', width: 50, align: 'center' },
                { header: '税率5', name: 'TaxRate5', width: 30, align: 'center' },
                { header: '税额5', name: 'Tax5', width: 30, align: 'center' },
                { header: '商品名称6', name: 'FeeType6', width: 60, align: 'center' },
                { header: '规格6', name: 'Model6', width: 30, align: 'center' },
                { header: '单位6', name: 'Unit6', width: 30, align: 'center' },
                { header: '数量6', name: 'QTY6', width: 30, align: 'center' },
                { header: '单价6', name: 'PRICE6', width: 50, align: 'center' },
                { header: '金额6', name: 'Amount6', width: 50, align: 'center' },
                { header: '税率6', name: 'TaxRate6', width: 30, align: 'center' },
                { header: '税额6', name: 'Tax6', width: 30, align: 'center' },
                { header: '商品名称7', name: 'FeeType7', width: 60, align: 'center' },
                { header: '规格7', name: 'Model7', width: 30, align: 'center' },
                { header: '单位7', name: 'Unit7', width: 30, align: 'center' },
                { header: '数量7', name: 'QTY7', width: 30, align: 'center' },
                { header: '单价7', name: 'PRICE7', width: 50, align: 'center' },
                { header: '金额7', name: 'Amount7', width: 50, align: 'center' },
                { header: '税率7', name: 'TaxRate7', width: 30, align: 'center' },
                { header: '税额7', name: 'Tax7', width: 30, align: 'center' },
                { header: '商品名称8', name: 'FeeType8', width: 60, align: 'center' },
                { header: '规格8', name: 'Model8', width: 30, align: 'center' },
                { header: '单位8', name: 'Unit8', width: 30, align: 'center' },
                { header: '数量8', name: 'QTY8', width: 30, align: 'center' },
                { header: '单价8', name: 'PRICE8', width: 50, align: 'center' },
                { header: '金额8', name: 'Amount8', width: 50, align: 'center' },
                { header: '税率8', name: 'TaxRate8', width: 30, align: 'center' },
                { header: '税额8', name: 'Tax8', width: 30, align: 'center' },
                { header: '购货名称', name: 'InvoiceTOMTitle', width: 50, align: 'center' },
                { header: '购货税号', name: 'InvoiceTOMTaxNo', width: 50, align: 'center' },
                { header: '购货地址', name: 'InvoiceTOMAddr', width: 50, align: 'center' },
                { header: '购货账号', name: 'InvoiceTOMAccount', width: 80, align: 'center' },
                { header: '制单人', name: 'UserDoc', width: 30, align: 'center' },
                { header: '复核人', name: 'UserVerify', width: 30, align: 'center' },
                { header: '收款人', name: 'UserGet', width: 30, align: 'center' },
                { header: '备注', name: 'Note', width: 80, align: 'center' },
            ];
            detailColData = [
                { header: '账单编号', name: 'BillNo', width: 100, align: 'center' },
                { header: '账单状态', name: 'BillStatus', width: 60, align: 'center' },
                { header: '顺序号', name: 'SeqNo', width: 30, align: 'right' },
                { header: '一级部门', name: 'DeptName1', width: 80, align: 'center' },
                { header: '二级部门', name: 'DeptName2', width: 80, align: 'center' },
                { header: '客户名称', name: 'CustomerName', width: 80, align: 'left' },
                { header: '业务流水号', name: 'OrderNo', width: 80, align: 'left' },
                { header: '业务类型', name: 'OrderType', width: 60, align: 'left' },
                { header: '客户名称', name: 'Currency', width: 80, align: 'left' },
                { header: '业务流水号', name: 'Exchange', width: 80, align: 'left' },
                { header: '业务类型', name: 'Amount', width: 60, align: 'left' },
                { header: '收入CNY', name: 'IncomeCNY', width: 60, align: 'left' },
                { header: '成本CNY', name: 'CostCNY', width: 60, align: 'left' },
                { header: '利润CNY', name: 'ProfitCNY', width: 60, align: 'left' },
            ]
            //排序
            defaultSort = { sortby: 'UID', sortdir: 'ASC' };
            //条件
            defaultWhere = { where: ' 1 = 1 ' };
            //初始化
            listGrid = $('#listgrid').omGrid({
                width: '100%',
                height: 'fit',
                //autoFit: true,
                //title: '支票列表',
                singleSelect: true,
                editMode: 'insert',
                onRowClick:function(rowIndex, rowData, event){
                    detailGrid.omGrid({
                        extraData: $.extend({ where: " InvoiceNo = '" + rowData.InvoiceNo + "'" }, { sortby: 'UID', sortdir: 'ASC' }),
                        dataSource: '../Handler/grid.ashx?view=vBillQuery',
                    });
                },
                limit: 20,
                extraData: $.extend(defaultWhere, defaultSort),
                dataSource: "{rows:[],total:0}",
                colModel: colData
            });
            detailGrid = $('#detailgrid').omGrid({
                width: '100%',
                height: 'fit',
                singleSelect: true,
                editMode: 'insert',
                limit: 20,
                extraData: $.extend({ where : ' 1=2 ' }, { sortby: 'UID', sortdir: 'ASC' }),
                dataSource: '',
                colModel: detailColData
            });
        });

        genRenderCheckbox = function (colValue, rowData, rowIndex) {
            if (colValue) {
                return '<input type="checkbox" id="00" checked="checked" disabled="disabled"></input>';
            }
            return '<input type="checkbox" id="01" disabled="disabled"></input>';
        }

        genRenderDateformatSS = function (colValue, rowData, rowIndex) {
            if (colValue.length == 0 || colValue == null) {
                return '';
            }
            else {
                if (colValue.indexOf("/Date") > -1)
                    return new Date(parseInt(colValue.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd");
                else
                    return colValue;
            }
        }

        genRenderDateformat = function (colValue, rowData, rowIndex) {
            if (colValue.length == 0 || colValue == null) {
                return '';
            }
            else {
                if (colValue.indexOf("/Date") > -1)
                    return new Date(parseInt(colValue.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd hh:mm");
                else
                    return colValue;
            }
        }
        //查询语句
        showSearchPanel = function () {
            $("#InvoiceDateFM").omCalendar();
            $("#InvoiceDateTO").omCalendar();
            $("#button-search").click(function () {
                var custWhere = ' AND InvoiceNo <> ""  ';
                if ($("#search-panel input[id='InvoiceDateFM']").val().length > 0) {
                    custWhere = " AND (InvoiceDate BETWEEN '" + $("#search-panel input[id='PurchaseDateStart']").val() + "' AND ";
                    if ($("#search-panel input[id='InvoiceDateTO']").val().length > 0) {
                        custWhere += " '" + $("#search-panel input[id='PurchaseDateEnd']").val() + "') "
                    }
                    else {
                        custWhere += " GETDATE()) "
                    }
                }
                if ($("#search-panel input[id='InvoiceNo']").val().length > 0) {
                    custWhere += ' AND InvoiceNo LIKE ' + '\'%' + $("#search-panel input[id='InvoiceNo']").val() + '%\'';

                }
                listGrid.omGrid({
                    extraData: $.extend({ where: defaultWhere.where + custWhere }, defaultSort),
                    dataSource: '../Handler/grid.ashx?view=vInvoice'
                });
                detailGrid.omGrid({
                    extraData: $.extend({ where: defaultWhere.where + custWhere }, defaultSort),
                    dataSource: ''
                });
            });
            $('#button-clear').click(function () {
                $("div[id='search-panel'] input").val("");
            });
            $('#button-import').click(function () {
                art.dialog.data('currentUID', currentUID);
                art.dialog.open('../IncomePages/ImportInvoice.aspx', {
                    id: 'ImportInvoice', width: 750, height: 500, title: '发票数据导入', lock: true,
                    close: function () {
                    }
                }, true);
            });
        };
    </script>
</head>
<body>
    <div id="west-panel" class="westpanel">
        <div id="search-panel">
            <table>
                <tr>
                    <td style="width: 60px" align="right">
                        <span class="label">开票日期</span>
                    </td>
                    <td>
                        <input type="text" class="input-text" id="InvoiceDateFM" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 60px" align="right">
                        <span class="label">到</span>
                    </td>
                    <td>
                        <input type="text" class="input-text" id="InvoiceDateTO" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 60px" align="right">
                        <span class="label">发票号码</span>
                    </td>
                    <td>
                        <input type="text" class="input-text" id="InvoiceNo" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div id="center-panel">
        <table id="listgrid"></table>
    </div>
    <div id="east-panel">
        <table id="detailgrid"></table>
    </div>
    <div id="south-panel">
        <table style="margin-top: 5px; margin-left: 20px;">
            <tr>
                <td>
                    <input id="button-search" type="button" class="btnCss" value="搜    索" />
                    <input id="button-clear" type="button" class="btnCss" value="清    空" style="margin-left: 20px;" />
                    <input id="button-import" type="button" class="btnCss" value="导    入" style="margin-left: 20px;" />
                </td>
            </tr>
        </table>
    </div>
</body>
</html>
